import { http } from "@/utils/http";
import { DeptModel } from "@/api/model/deptModel";
import { BaseTree } from "@/api/model/baseModel";

enum Api {
  BaseTree = "/dept/tree",
  DeptTree = "/dept/children",
  SaveDept = "/dept/save",
}

export function getBaseTree(parentId: string) {
  return http.get<BaseTree[]>({
    url: Api.BaseTree,
    params: { parentId },
  });
}

export function checkCode(code: string, id?: string) {
  return http.get<Boolean>({
    url: `/dept/check/${code}`,
    params: { id },
  });
}

export function saveDept(dept: DeptModel) {
  return http.post<DeptModel>({
    url: Api.SaveDept,
    params: dept,
  });
}

export function getDeptTree(parentId?: string) {
  return http.get<DeptModel[]>({
    url: Api.DeptTree,
    params: { parentId },
  });
}

export function changeState(id: string, state: boolean) {
  return http.post<Boolean>({
    url: `/dept/state/${id}/${state}`,
  });
}

export function deleteDept(id: string) {
  return http.post<string>({
    url: `/dept/deleteDept/${id}`,
  });
}
